<?php
	
	include("../Conection.php"); 
	include("../JSON.php"); 
	
	
		//definicion de la clase
	class Menu {		
		
		// contructor
		public function __construct(){
			//echo "constructor de clase cliente";
			$this->obj_cnx = new Connection();
		}
	
	
		public function get_all() {
			if($this->obj_cnx->getConnect()) {
			
				$query = "SELECT m.id, p.nombre_prod, s.sabor, m.tamano, m.precio FROM menu as m
					left join producto as p on m.id_prod = p.id
					left join sabor as s on m.id_sabor = s.id";
				$res = mysql_query($query);
				
				$json = new Services_JSON();
				$data = array();
				
				$init_json = '{"total_count":"' . mysql_num_rows($res) . '","data":';
					
				while($row = mysql_fetch_array($res)){
					//echo utf8_encode($row['sabor']);
					array_push($data,array("id"=>$row['id'], "producto"=>$row['nombre_prod'], "sabor"=>utf8_encode($row['sabor']),
					"tamano"=> $row['tamano'], "precio" =>$row['precio'], "full"=>$row['nombre_prod']." - ".utf8_encode($row['sabor'])." - ".$row['tamano']));
				}
				
				$json_string = $json->encode($data);
				
				$json_final = $init_json . $json_string . '}';
				
				echo $json_final;
				
				return $res;
			}
		}
	}

	//fin de clase	
	?>
	<?php
		$menu = new Menu();
		
		if(!isset($_GET['accion']))
			$_GET['accion'] = "list";
		
		switch($_GET['accion']) {
			
			case 'list':
				$rs = $menu->get_all();
				break;
						
		}	
	?>
